﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Business.vo;
using Business.exception;

namespace Business.dao
{
    internal class ImageLinkDao : AbstractDao
    {

        public ImageLink GetById(Int32 id)
        {
            ImageLink imagelink = null;

            try
            {
                imagelink = mapper.QueryForObject<ImageLink>("ImageLink.selectById", id);

            }
            catch (System.Exception ex)
            {
                log.Error(ex);
                throw new WebSiteException("Error retrieving imagelink from database", ex);
            }

            return imagelink;
        }

        public IList<ImageLink> GetAll()
        {
            IList<ImageLink> imagelinks = null;

            try
            {
                imagelinks = mapper.QueryForList<ImageLink>("ImageLink.selectAll", null);
            }
            catch (System.Exception ex)
            {
                log.Error(ex);
                throw new WebSiteException("Error retrieving imagelinks from database", ex);
            }

            return imagelinks;
        }

        public IList<ImageLink> GetAllNames()
        {
            IList<ImageLink> imagelinks = null;

            try
            {
                imagelinks = mapper.QueryForList<ImageLink>("ImageLink.selectAllNames", null);
            }
            catch (System.Exception ex)
            {
                log.Error(ex);
                throw new WebSiteException("Error retrieving imagelinks from database", ex);
            }

            return imagelinks;
        }


        public void Save(ImageLink imagelink)
        {
            try
            {
                mapper.Insert("ImageLink.insert", imagelink);
            }
            catch (System.Exception ex)
            {
                log.Error(ex);
                throw new WebSiteException("Error retrieving imagelinks from database", ex);
            }
        }


        public void Update(ImageLink imagelink)
        {
            try
            {
                mapper.Update("ImageLink.update", imagelink);
            }
            catch (System.Exception ex)
            {
                log.Error(ex);
                throw new WebSiteException("Error retrieving imagelinks from database", ex);
            }
        }

        public void Delete(Int32 id)
        {
            try
            {
                mapper.Delete("ImageLink.deleteById", id);
            }
            catch (System.Exception ex)
            {
                log.Error(ex);
                throw new WebSiteException("Error retrieving imagelinks from database", ex);
            }
        }
    }
}
